package com.sxj.corejava.code07_面向对象.多态;

import java.util.Scanner;

/**
 * @author 石小俊
 * @date 2024年03月21日 19:08
 * 去宠物店领养宠物, 可以选择三种宠物 1.狗狗 2.猫咪 3.猪猪
 * 宠物Pet存在两个属性:name(姓名)、gender(性别)
 * 狗狗Dog存在一个自己的属性:age(年龄)
 * 猫咪Cat存在一个自己的属性:type(品种)
 * 猪猪Pig存在一个自己的属性:hobby(爱好)
 * 每一个宠物都有一个show方法, 用于打印对应的宠物信息
 * 通过用户输入不同选项选择对应宠物,打印出对应宠物的信息
 */
public class Test02_练习 {

    public static void main(String[] args) {
        showMenu();
    }

    public static void showMenu() {
        Scanner sc = new Scanner(System.in);
        System.out.println("******************欢迎来到紫金宠物店******************");
        System.out.print("请选择需要领养的宠物(1.狗狗 2.猫咪 3.猪猪 4.退出):");
        int choice = sc.nextInt();
        // 定义父类的引用
        Pet pet = null;
        switch (choice) {
            case 1:
                // 对于不同子类,指向不同的子类对象
                pet = new Dog("旺财", "公", 5);
                pet.show();
                showMenu();
                break;
            case 2:
                pet = new Cat("汤姆", "公", "英短");
                pet.show();
                showMenu();
                break;
            case 3:
                pet = new Pig("佩琪", "母", "跳泥坑");
                pet.show();
                showMenu();
                break;
            case 4:
                System.out.println("您已离开紫金宠物店,欢迎下次光临!");
                break;
            default:
                System.out.println("您输入的选项有误,请重新输入!");
                showMenu();
                break;
        }
    }

}

class Pet {
    private String name;
    private String gender;

    public Pet(String name, String gender) {
        this.name = name;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void show() {
        System.out.println("我是一只宠物,我的名字叫做:" + name + ",性别:" + gender);
    }
}

class Dog extends Pet {
    private int age;

    public Dog(String name, String gender, int age) {
        super(name, gender);
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        System.out.println("我是一只狗,我的名字叫做:" + getName() + ",性别:" + getGender() + ",年龄:" + age);
    }
}

class Cat extends Pet {
    private String type;

    public Cat(String name, String gender, String type) {
        super(name, gender);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void show() {
        System.out.println("我是一只" + type + "猫,我的名字叫做:" + getName() + ",性别:" + getGender());
    }
}

class Pig extends Pet {
    private String hobby;

    public Pig(String name, String gender, String hobby) {
        super(name, gender);
        this.hobby = hobby;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    public void show() {
        System.out.println("我是一只宠物猪,我的名字叫做:" + getName() + ",性别:" + getGender() + ",我的爱好是:" + hobby);
    }
}
